$(document).ready(function(){
    var VAL ={
        NORMAL     : "0000000"  ,
        EVT_USER   : $("#userId").text(),
        T_FIPINQSHT  : "FIPINQSHT",
        T_FBPBISOPE	 : 'FBPBISOPE',
        T_FBPBISTOL  : 'FBPBISTOL',
        T_FIPINQBOX  : 'FIPINQBOX',
        T_FPPIWIPEQ  : 'FPPIWIPEQ',
        T_FPPMVINCCL : 'FPPMVINCCL'
    };

    var domObj = {
        cassetteListDiv : $("#cassetteListDiv"),
        cassetteListGrd : $("#cassetteListGrd"),
        cassetteGrdPg : "#cassetteGrdPg",

        selectSheetListDiv : $("#selectSheetListDiv"),
        selectSheetListGrd : $("#selectSheetListGrd"),
        selectSheetPg : "#selectSheetListPg",

        selectedSheetListDiv : $("#selectedSheetListDiv"),
        selectedSheetListGrd : $("#selectedSheetListGrd"),
        selectedSheetPg : "#selectedSheetListPg",

        cassetteCnt : $("#cassetteCnt"),
        sheetCnt : $("#sheetCnt"),
        glassCnt : $("#glassCnt")

    };

    var controlsQuery = {
        W                  : $(window),
        opeSelect          : $("#opeSelect"),
        toolIdSel          : $("#toolIdSel"),
        toolPortIdSel      : $("#toolPortIdSel"),
        cassetteIdTxt	   : $("#cassetteIdTxt"),
        toolExplain        : $("#toolExplain"),
        toolOperateMode    : $("#toolOperateMode"),
        toolStat      	   : $("#toolStat"),
        toolType           : $("#toolType"),
        toolClass          : $("#toolClass"),
        toolStatExplain    : $("#toolStatExplain"),

        tabopeSelect          : $("#tabopeSelect"),
        tabtoolIdSel          : $("#tabtoolIdSel"),
        tabtoolPortIdSel      : $("#tabtoolPortIdSel"),
        tabcassetteIdTxt	  : $("#tabcassetteIdTxt"),
        tabtoolExplain        : $("#tabtoolExplain"),
        tabtoolOperateMode    : $("#tabtoolOperateMode"),
        tabtoolStat      	  : $("#tabtoolStat"),
        tabtoolType           : $("#tabtoolType"),
        tabtoolClass          : $("#tabtoolClass"),
        tabtoolStatExplain    : $("#tabtoolStatExplain"),

        cusOrderId		   : $("#cusOrderId"),
        mdlId			   : $("#mdlId"),
        pathId             : $("#pathId"),

        tabcusOrderId		   : $("#tabcusOrderId"),
        tabmdlId			   : $("#tabmdlId"),
        tabpathId              : $("#tabpathId"),

        selProNum			   : $("#selProNum"),
        selChipCnt			   : $("#selChipCnt")


    };

    var btnQuery = {
        query  			: $("#query_btn"),
        cassetteCancel  : $("#cassette_cancel_btn"),
        fresh  		 	: $("#fresh_btn"),
        moveInCancel	: $("#moveIn_cancel_btn")
    };

    /**
     * Bind button click action
     */
    var iniButtonAction = function(){
        btnQuery.query.click(function(){
            btnFunc.query_func();
        });
        btnQuery.cassetteCancel.click(function(){
            btnFunc.cassetteCancel_func();
        });
        btnQuery.fresh.click(function(){
            btnFunc.fresh_func();
        });
        btnQuery.moveInCancel.click(function(){
            btnFunc.moveInCancel_func();
        });
    };

    var btnFunc = {
        query_func:function(){
            var box_id = controlsQuery.cassetteIdTxt.val();
            var port_id = controlsQuery.toolPortIdSel.val();
            var tool_id = controlsQuery.toolIdSel.find("option:selected").val();

            if(!tool_id){
                showErrorDialog("","请选择设备代码！");
                return;
            }
            if (!port_id) {
                showErrorDialog("","请选择port代码！");
                return;
            }

            $("#cassetteListGrd").jqGrid("clearGridData");
            var inTrxObj ={
                trx_id     : VAL.T_FIPINQBOX,
                action_flg : 'C'        ,
//       	         box_id 	: box_id,
                tool_id    : tool_id,
                tool_port_id_fk : port_id,
                box_stat   : 'INPR'
            };
            if(!box_id){
                inTrxObj.box_id = box_id
            }
            var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                setGridInfo(outTrxObj.oary_box,"#cassetteListGrd");
                setCntInfo();
            }

        },
        cassetteCancel_func:function(){
            var rowId = domObj.cassetteListGrd.jqGrid('getGridParam','selrow');
            var rowData = domObj.cassetteListGrd.jqGrid('getRowData',rowId);
            if(!rowId){
                showErrorDialog("001","请选择要释放的箱号！");
                return false;
            }
            var box_id = rowData.box_id;
            if(!box_id){
                showErrorDialog("02","请选择要释放的箱号！");
                return false;
            }
//         var  box_stat = rowData.box_stat;
            var prd_qty = rowData.prd_qty;
            var chip_qty = rowData.chip_qty;
            var inTrxObj ={
                trx_id     : VAL.T_FPPMVINCCL,
                action_flg : 'B'        ,
                box_id 	: box_id,
                prd_qty	: prd_qty,
                chip_qty	: chip_qty,
                evt_usr	: 'C1602020',
                opi_ope_flg: "Y",
            };
            var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                showSuccessDialog("卡匣取消成功！");
                btnFunc.query_func();
            }
        },
        moveInCancel_func:function(){
            var box_id = controlsQuery.tabcassetteIdTxt.val();
            if(!box_id){
                showErrorDialog("", "请输入卡匣代码");
                return false;
            }
            var selectBoxRowId = domObj.selectedSheetListGrd.jqGrid('getDataIDs');;
            if(selectBoxRowId.length <= 0){
                showErrorDialog("","请选择要取消的玻璃！");
                return false;
            }


            /*** 将Div实例化为modal窗体 ***/
            function diaLogRemarkFnc(){

                var remarkTxt = $("#remarkDialog_inputTxt").val();
                var opeSelVal = controlsQuery.tabopeSelect.find("option:selected").val();
                if(opeSelVal){
                    var ope_id = opeSelVal.split("@")[0];
                }
                var tool_id = controlsQuery.tabtoolIdSel.find("option:selected").val();
                var port_id = controlsQuery.tabtoolPortIdSel.find("option:selected").val();
                var iaryA = new Array();
                var inObj;
                var rows =domObj.selectedSheetListGrd.jqGrid('getGridParam','data');
                for (var int = 0; int < rows.length; int++) {
                    inObj = {
                        prd_seq_id:rows[int]["prd_seq_id"],
                        slot_no	  :rows[int]["slot_no"]
                    };
                    iaryA[int] = inObj;
                }
                var inTrxObj ={
                    trx_id     : VAL.T_FPPMVINCCL,
                    action_flg : 'C'        ,
                    box_id 	: box_id,
                    ope_id		: ope_id,
                    tool_id	: tool_id,
                    port_id	: port_id,
                    sht_ope_msg: remarkTxt,
                    evt_usr	: 'C1602020',
                    prd_qty    : rows.length,
                    iary		: iaryA,
                    opi_ope_flg: "Y",
                };
                var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                    $('#remarkDialog').modal("hide");
                    showSuccessDialog("玻璃入账取消成功！");
                    domObj.selectedSheetListGrd.jqGrid("clearGridData");
                    toolFunc.iniSelectSheetList();
                    controlsQuery.tabcassetteIdTxt.val("");
                }

            }

            $('#remarkDialog').modal({
                backdrop : 'static',
                keyboard:false,
                show:false
            });
            $('#remarkDialog').unbind('shown.bs.modal');
            $("#remarkDialog_moveinBtn").unbind('click');

            $('#remarkDialog').bind('shown.bs.modal');
            $('#remarkDialog').modal("show");
            $("#remarkDialog_moveinBtn").bind('click',diaLogRemarkFnc);
            $("#remarkDialog input").attr({'disabled':false});
        },
        //fresh func
        fresh_func:function(){
            location.reload();
        },
    };


    var iniGridInfo = function(){
        var cassetteGrdInfoCM = [
            {name: 'box_id',   		index: 'box_id',   		label: CASSETTE_NO_TAG    , width: 80},
            {name: 'prty', 			index: 'prty',			label: PRTY_TAG    , 		width: 80},
            {name: 'box_stat',		index: 'box_stat', 		label: STATUS_TAG,			width: 80},
            {name: 'prd_qty',    	index: 'prd_qty',   	label: GLASS_NUM_TAG  , 	width: 80},
            {name: 'chip_qty',     	index: 'chip_qty',   	label: SHEET_NUM_TAG  , 	width: 80}
        ];
        domObj.cassetteListGrd.jqGrid({
            url:"",
            datatype:"local",
            mtype:"POST",
            height:200,
            autowidth : true,
            shrinkToFit:true,
            scroll:true,
            rownumWidth : true,
            resizable : true,
            rowNum:40,
            loadonce:true,
            fixed:true,
            viewrecords:true,
//            multiselect : true,
            pager : domObj.cassetteGrdPg,
            colModel: cassetteGrdInfoCM,
            onSelectRow: function(id){
                var rowData = $(this).jqGrid("getRowData",id);
                console.log(rowData);
                if (rowData.box_id !=null) {
                    var boxid = rowData.box_id;
                }
                var inTrxObj ={
                    trx_id     : VAL.T_FIPINQBOX,
                    action_flg : 'Q'        ,
                    box_id : boxid
                };
                var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                    controlsQuery.cusOrderId.html(outTrxObj.so_id_fk);
                    controlsQuery.mdlId.html(outTrxObj.mdl_id_fk);
                    controlsQuery.pathId.html(outTrxObj.nx_path_id_fk);
                }
            }
        });

        var selectSheetinfoCM = [
            {name: 'prd_seq_id',   	    index: 'prd_seq_id', 	 label: SHEET_ID_TAG    ,    width: 120},
            {name: 'pv_box_id_fk',   index: 'pv_box_id_fk',label: LOGON_BOX_TAG    , 	 width: 60},
            {name: 'slot_no',		    index: 'slot_no', 		 label: PPBOX_SLOT_NO_TAG,	 width: 40},
            {name: 'prd_qty',		    index: 'prd_qty', 		 label: PANEL_NUM_TAG,		 width: 60},
            {name: 'mdl_id_fk',    	    index: 'mdl_id_fk',   	 label: PRODUCT_ID_TAG  , 	 width: 100},
            {name: 'wo_id',          index: 'wo_id',   	 label: WO_ID_TAG  , 	 	 width: 100},
            {name: 'cr_proc',           index: 'cr_proc',   	 label: PROC_ID_TAG  , 		 width: 80},
            {name: 'logon_timestamp',   index: 'logon_timestamp',label: LOGON_TIMESTAMP_TAG, width: 180}
        ];
        domObj.selectSheetListGrd.jqGrid({
            url:"",
            datatype:"local",
            mtype:"POST",
            height:180,
//        width:domObj.selectSheetListDiv.width(),
            width:700,
            shrinkToFit:true,
            scroll:true,
            rownumWidth : true,
            resizable : true,
            rowNum:40,
            loadonce:true,
            fixed:true,
            viewrecords:true,
            multiselect : true,
            pager : domObj.selectSheetPg,
            colModel: selectSheetinfoCM,
            onSelectRow: function(){
                toolFunc.selectRow();
            },
            onSelectAll: function(){
                toolFunc.selectRow();
            }
        });



        var selectedSheetinfoCM = [
            {name: 'prd_seq_id',   	    index: 'prd_seq_id', 	 label: SHEET_ID_TAG    ,    width: 120},
            {name: 'pv_box_id_fk',   index: 'pv_box_id_fk',label: LOGON_BOX_TAG    , 	 width: 60},
            {name: 'slot_no',		    index: 'slot_no', 		 label: PPBOX_SLOT_NO_TAG,	 width: 40},
            {name: 'prd_qty',		    index: 'prd_qty', 		 label: PANEL_NUM_TAG,		 width: 60},
            {name: 'mdl_id_fk',    	    index: 'mdl_id_fk',   	 label: PRODUCT_ID_TAG  , 	 width: 100},
            {name: 'wo_id',          index: 'wo_id',   	 label: WO_ID_TAG  , 	 	 width: 100},
            {name: 'cr_proc',           index: 'cr_proc',   	 label: PROC_ID_TAG  , 		 width: 80},
            {name: 'logon_timestamp',   index: 'logon_timestamp',label: LOGON_TIMESTAMP_TAG, width: 180}
        ];
        domObj.selectedSheetListGrd.jqGrid({
            url:"",
            datatype:"local",
            mtype:"POST",
            height:180,
//        width:domObj.selectedSheetListDiv.width(),
            width:700,
            shrinkToFit:false,
            scroll:true,
            rownumWidth : true,
            resizable : true,
            rowNum:40,
            loadonce:true,
            fixed:true,
            viewrecords:true,
//        multiselect : true,
            pager : domObj.selectedSheetPg,
            colModel: selectedSheetinfoCM
        });
    }

    var toolFunc = {
        clearFunc : function(){
        },
        selectRow:function(){
            var box_id = controlsQuery.tabcassetteIdTxt.val();
            if (!box_id) {
                showErrorDialog("","请输入卡匣代码！");
                return;
            }

            /**勾选一张表改变另一张表**/
            domObj.selectedSheetListGrd.jqGrid("clearGridData");
            var rowIds = domObj.selectSheetListGrd.jqGrid('getGridParam', 'selarrrow');
            selectRowIdsLen = rowIds.length;
            for( iRow = 0; iRow<selectRowIdsLen; iRow++){
                selectRow = domObj.selectSheetListGrd.jqGrid("getRowData", rowIds[iRow]);
                domObj.selectedSheetListGrd.jqGrid("addRowData",iRow,selectRow);
            }

            /**给卡匣信息赋值**/
            var rows =domObj.selectedSheetListGrd.jqGrid('getGridParam','data');
            controlsQuery.selProNum.html(rows.length);


            /**给产品信息赋值**/
            var pro_id ,selChipCnt = 0;
            if(rows.length === 0){
                controlsQuery.tabcusOrderId.html("");
                controlsQuery.tabmdlId.html("");
                controlsQuery.tabpathId.html("");
                controlsQuery.selChipCnt.html(selChipCnt);
            }
            for (var int = 0; int < rows.length; int++) {
                selChipCnt += parseInt(rows[int]["prd_qty"]);
                pro_id = rows[int]["prd_seq_id"];
                var inTrxObj ={
                    trx_id     : VAL.T_FIPINQSHT,
                    action_flg : 'Q'        ,
                    prd_seq_id : pro_id
                };
                var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                    if(int != 0){
                        if(controlsQuery.tabcusOrderId.html() != outTrxObj.so_id_fk){
                            showErrorDialog("","客户订单号不一致");
                            return;
                        };
                        if(controlsQuery.tabmdlId.html() != outTrxObj.mdl_id_fk){
                            showErrorDialog("","产品名称不一致");
                            return;
                        };
                        if(controlsQuery.tabpathId.html() != outTrxObj.cr_path_id_fk){
                            showErrorDialog("","工艺路线不一致");
                            return;
                        };

                    };
                    controlsQuery.tabcusOrderId.html(outTrxObj.so_id_fk);
                    controlsQuery.tabmdlId.html(outTrxObj.mdl_id_fk);
                    controlsQuery.tabpathId.html(outTrxObj.cr_path_id_fk);
                }
            }
            controlsQuery.selChipCnt.html(selChipCnt);
        },
        setOpeSelectDate : function(dataCnt, arr, selVal, selVal2, selTxt, selVal3, queryObj){
            var i, realCnt;

            queryObj.empty();
            realCnt = parseInt( dataCnt, 10);

            if( realCnt == 1 ){
                queryObj.append("<option value="+ arr[selVal] + "@" + arr[selVal2] +"@"+arr[i][selVal3]+">"+ arr[selTxt] +"</option>");
            }else if( realCnt > 1 ){
                for( i = 0; i < realCnt; i++ ){
                    queryObj.append("<option value="+ arr[i][selVal] + "@" + arr[i][selVal2] + "@"+arr[i][selVal3]+">"+ arr[i][selTxt] +"</option>");
                }
            }
            queryObj.select2({
                theme : "bootstrap"
            });
        },
        iniOpeSelect : function(){
            SelectDom.setSelect($("select"), "", "");
            var inObj, outObj;

            inObj = {
                trx_id      : VAL.T_FBPBISOPE,
                action_flg  : 'L'
            };
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                toolFunc.setOpeSelectDate(outObj.tbl_cnt, outObj.oary, "ope_id", "ope_ver", "ope_id","tool_run_mode", controlsQuery.opeSelect);
                toolFunc.setOpeSelectDate(outObj.tbl_cnt, outObj.oary, "ope_id", "ope_ver", "ope_id","tool_run_mode", controlsQuery.tabopeSelect);
            }
        },
        iniToolSel: function(toolObj,opeObj){
            toolObj.empty();
            var opeSelVal = opeObj.find("option:selected").val();
            if(opeSelVal){
                var selectedMode = opeSelVal.split("@")[2];
            }
            var inObj, outObj;
            var iary = {
                tool_run_mode : selectedMode,
                unit_typ      : "MAIN"
            };
            inObj = {
                trx_id      : VAL.T_FBPBISTOL,
                action_flg  : 'H',
                iary		 : [iary]
            };
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                SelectDom.addSelectArr(toolObj, outObj.oary, "tool_id","tool_id");
            }
            toolObj.select2({
                theme : "bootstrap"
            });
        },
        iniPortSel: function(portObj,toolObj){
            portObj.empty();
            var toolSelVal = toolObj.find("option:selected").val();
            var inObj, outObj;
            var iary = {
                tool_id : toolSelVal,
                port_typ: 'L'
            }
            inObj = {
                trx_id    : VAL.T_FBPBISTOL,
                action_flg: 'I',
                iary	  : [iary]
            }
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                SelectDom.addSelectArr(portObj, outObj.oaryB, "port_id","port_id");
            }
            portObj.select2({
                theme : "bootstrap"
            });

        },
//	        iniCassetteList:function(){
//	        	$("#cassetteListGrd").jqGrid("clearGridData");
//	        	var toolSelVal = controlsQuery.toolIdSel.find("option:selected").val();
//	        	 var inTrxObj ={
//	        	         trx_id     : VAL.T_FIPINQBOX,
//	        	         action_flg : 'D'        ,
//	        	         tool_id : toolSelVal
//	        	      };
//	        	      var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
//	        	      if(  outTrxObj.rtn_code == VAL.NORMAL ) {
//	        	         setGridInfo(outTrxObj.oary_box,"#cassetteListGrd");
//	        	         setCntInfo();
//	        	      }
//	        },
        iniSelectSheetList:function(){
            $("#selectSheetListGrd").jqGrid("clearGridData");
            var tool_id = controlsQuery.tabtoolIdSel.find("option:selected").val();
            var ope_info = controlsQuery.tabopeSelect.find("option:selected").val();
            ope_info_ary = ope_info.split("@");
            ope_id = ope_info_ary[0];
            ope_ver = ope_info_ary[1];
            var inTrxObj ={
                trx_id : VAL.T_FPPIWIPEQ,
                action_flg: 'S',
                cr_ope_id : ope_id,
                cr_ope_ver: ope_ver,
                tool_id   : tool_id
            };
            var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                setGridInfo(outTrxObj.oary_prd,"#selectSheetListGrd");
            }

        },
        iniToolInfo:function(toolObj,explainObj,operateObj,statObj,typeObj,classObj,statExplainObj){
            var tool_dsc,tool_ctrl_mode,tool_stat,unit_typ,tool_cate,toolStat_dsc;
            var toolSelVal = toolObj.find("option:selected").val();
            var iary = {
                tool_id : toolSelVal
            };
            var inTrxObj = {
                trx_id     : VAL.T_FBPBISTOL,
                action_flg : 'I'        ,
                iary       : [iary]
            }
            var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if(  outTrxObj.rtn_code == VAL.NORMAL ) {
                tool_dsc =outTrxObj.oary[0]["tool_dsc"];
                tool_ctrl_mode =outTrxObj.oary[0]["tool_ctrl_mode"];
                tool_stat =outTrxObj.oary[0]["tool_stat"];
                unit_typ =outTrxObj.oary[0]["unit_typ"];
                tool_cate =outTrxObj.oary[0]["tool_cate"];

                var iaryA = {
                    data_cate : 'EQST'   ,
                    data_id	  : tool_stat
                };
                var inObj = {
                    trx_id      : 'FBPBISDAT' ,
                    action_flg : 'Q'        ,
                    iary        : [iaryA]
                };
                var  outObj = comTrxSubSendPostJson(inObj);
                if(  outObj.rtn_code == "0000000" ) {
                    toolStat_dsc = outObj.oary[0]["data_desc"];
                }
                explainObj.html(tool_dsc);
                operateObj.html(tool_ctrl_mode);
                statObj.html(tool_stat);
                typeObj.html(unit_typ);
                classObj.html(tool_cate);
                statExplainObj.html(toolStat_dsc);

            }
        }
    };

    var iniContorlData = function(){
        //Ope info
        toolFunc.iniOpeSelect();
        controlsQuery.cassetteIdTxt.val("");
        controlsQuery.tabcassetteIdTxt.val("");
        //Tool info
        toolFunc.iniToolSel(controlsQuery.toolIdSel,controlsQuery.opeSelect);
        toolFunc.iniToolSel(controlsQuery.tabtoolIdSel,controlsQuery.tabopeSelect);

        //Port info
        toolFunc.iniPortSel(controlsQuery.toolPortIdSel,controlsQuery.toolIdSel);
        toolFunc.iniPortSel(controlsQuery.tabtoolPortIdSel,controlsQuery.tabtoolIdSel);

        //Tool info
        toolFunc.iniToolInfo(controlsQuery.toolIdSel,controlsQuery.toolExplain,
            controlsQuery.toolOperateMode,controlsQuery.toolStat,controlsQuery.toolType,
            controlsQuery.toolClass,controlsQuery.toolStatExplain);
        toolFunc.iniToolInfo(controlsQuery.tabtoolIdSel,controlsQuery.tabtoolExplain,
            controlsQuery.tabtoolOperateMode,controlsQuery.tabtoolStat,controlsQuery.tabtoolType,
            controlsQuery.tabtoolClass,controlsQuery.tabtoolStatExplain);

        //CassetteList info
//        toolFunc.iniCassetteList();
        btnFunc.query_func();

        controlsQuery.opeSelect.change(function(){
            toolFunc.iniToolSel(controlsQuery.toolIdSel,controlsQuery.opeSelect);

            toolFunc.iniPortSel(controlsQuery.toolPortIdSel,controlsQuery.toolIdSel);
            toolFunc.iniToolInfo(controlsQuery.toolIdSel,controlsQuery.toolExplain,
                controlsQuery.toolOperateMode,controlsQuery.toolStat,controlsQuery.toolType,
                controlsQuery.toolClass,controlsQuery.toolStatExplain);
//        	toolFunc.iniCassetteList();
            btnFunc.query_func();

        });
        controlsQuery.tabopeSelect.change(function(){
            toolFunc.iniToolSel(controlsQuery.tabtoolIdSel,controlsQuery.tabopeSelect);

            toolFunc.iniPortSel(controlsQuery.tabtoolPortIdSel,controlsQuery.tabtoolIdSel);
            toolFunc.iniToolInfo(controlsQuery.tabtoolIdSel,controlsQuery.tabtoolExplain,
                controlsQuery.tabtoolOperateMode,controlsQuery.tabtoolStat,controlsQuery.tabtoolType,
                controlsQuery.tabtoolClass,controlsQuery.tabtoolStatExplain);
            //selectSheetList info
            toolFunc.iniSelectSheetList();
        });

        controlsQuery.toolIdSel.change(function(){
            toolFunc.iniPortSel(controlsQuery.toolPortIdSel,controlsQuery.toolIdSel);
            toolFunc.iniToolInfo(controlsQuery.toolIdSel,controlsQuery.toolExplain,
                controlsQuery.toolOperateMode,controlsQuery.toolStat,controlsQuery.toolType,
                controlsQuery.toolClass,controlsQuery.toolStatExplain);
//        	toolFunc.iniCassetteList();
            btnFunc.query_func();
        });
        controlsQuery.tabtoolIdSel.change(function(){
            toolFunc.iniPortSel(controlsQuery.tabtoolPortIdSel,controlsQuery.tabtoolIdSel);
            toolFunc.iniToolInfo(controlsQuery.tabtoolIdSel,controlsQuery.tabtoolExplain,
                controlsQuery.tabtoolOperateMode,controlsQuery.tabtoolStat,controlsQuery.tabtoolType,
                controlsQuery.tabtoolClass,controlsQuery.tabtoolStatExplain);
            toolFunc.iniSelectSheetList();
        });
        setCntInfo();
    };

    var setCntInfo = function(){
        var rows = domObj.cassetteListGrd.jqGrid('getRowData');
        var rowNum = domObj.cassetteListGrd.jqGrid('getGridParam','records');
        var total = domObj.cassetteListGrd.jqGrid('getGridParam', 'records');
        var proCnt=0,chipCnt=0;
        domObj.cassetteCnt.html(rowNum);
        for (var int = 0; int < rowNum; int++) {
            proCnt += parseInt(rows[int]["prd_qty"]);
            chipCnt += parseInt(rows[int]["chip_qty"]);
        }
        domObj.sheetCnt.html(proCnt);
        domObj.glassCnt.html(chipCnt);

    }

    var initializationFunc = function(){
        iniGridInfo();
        iniButtonAction();
        iniContorlData();
    };
    initializationFunc();
    //模态框拖动
    $(".modal-content").draggable();
    //表格自适应
    function resizeFnc(){
        //1
        var offsetBottom,divWidth,offsetBottom1,divWidth1,offsetBottom2, divWidth2;
        divWidth = $("#divTable1").width();
        offsetBottom =  $(window).height() - $("#divTable1").offset().top;
        $("#divTable1").height(offsetBottom * 0.95);
        $("#cassetteListGrd").setGridWidth(divWidth * 0.35);
        $("#cassetteListGrd").setGridHeight(offsetBottom * 0.95 - 480);
        // 2
        divWidth1 = $("#divTable1").width();
        offsetBottom1 =  $(window).height() - $("#divTable1").offset().top;
        $("#divTable1").height(offsetBottom1 * 0.30);
        $("#selectSheetListGrd").setGridWidth(divWidth1 * 0.45);
        $("#selectSheetListGrd").setGridHeight(offsetBottom1 * 0.28-61);
        // // //3
        divWidth2 = $("#divTable1").width();
        offsetBottom2 = $(window).height() - $("#divTable1").offset().top;
        $("#divTable1").height(offsetBottom2 * 0.35);
        $("#selectedSheetListGrd").setGridWidth(divWidth2 * 0.45);
        $("#selectedSheetListGrd").setGridHeight(offsetBottom2 * 0.30-51);
    };
    resizeFnc();
    $(window).resize(function() {
        resizeFnc();
    });

});